<?php
/**
 * TomatoCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: list.phtml 4193 2010-08-01 16:33:56Z huuphuoc $
 * @since		2.0.2
 */
?>
<?php 
$this->headTitle($this->translator('tag_list_page_title'));
$this->headLink()->appendStylesheet($this->APP_STATIC_SERVER . '/skins/admin/default/css/form.css');
$this->headLink()->appendStylesheet($this->APP_STATIC_SERVER . '/skins/admin/default/css/tag.css');
?>
<div id="r-heading">
    <img src="<?php echo $this->APP_STATIC_SERVER . '/skins/admin/default/images/article.png'; ?>" alt=""/>
    <span><?php echo $this->translate('tag_list_breadcrumb') ?></span>
</div>
<?php
$massage = $this->flashMessenger();
if ($massage) {
    ?>
    <div id="message"><?php echo $massage; ?></div>
<?php } ?>

<div style="float:left; width: 40%;">
    <form method="post" action="<?php echo $this->url(array(), 'tag_tag_list'); ?>">
            <?php echo $this->translator('tag_list_search_guide'); ?>:
            <br />
            <input type="text" name="keyword" value="<?php if ($this->keyword != '') : ?><?php echo $this->escape($this->keyword); ?><?php endif; ?>" style="width: 250px" /> 
            <button class="button" type="submit"><span><?php echo $this->translator('tag_list_search_button'); ?></span></button>
    </form>
</div>
	
<?php if ($this->allow('add')) : ?>
<div class="vertical-separator">
    <?php echo $this->translator('tag_list_or'); ?>
</div>

<div style="float:left; width: 40%;">
        <form method="post" action="<?php echo $this->url(array(), 'tag_tag_add'); ?>">
                <?php echo $this->translator('tag_list_add_guide'); ?>:<br />
                <input type="text" name="keyword" style="width: 250px" />
                <button class="button" type="submit"><span><?php echo $this->translator('tag_list_add_button'); ?></span></button> 
        </form>
</div>	
<?php endif; ?>
<div class="clearfix"></div>
<div id="tags">
	<?php if ($this->numTags == 0) : ?>
	<div >
		<?php echo $this->translator('tag_list_no_tags'); ?>
	</div>
	<?php else : ?>
	<div style="margin-bottom: 10px;">
		<?php echo sprintf($this->translator('tag_list_found_tags'), $this->numTags); ?>: (<?php if ($this->allow('delete')) : ?><?php echo $this->translator('tag_list_delete_guide'); ?><?php endif; ?>)
	</div>
	
	<div>
		<?php foreach ($this->tags as $tag) : ?>
		<span id="tag_<?php echo $tag->id; ?>"><a href="javascript: void(0);"><?php echo $tag->text; ?></a></span>
		<?php endforeach; ?>
		<div class="clearfix"></div>
	</div>
	
	<div class="t_a_bottom t_a_ui_paginator">
		<?php echo $this->paginator()->slide($this->paginator, $this->paginatorOptions); ?>
	</div>
	<?php endif; ?>
</div>


<script type="text/javascript">
<?php if ($this->allow('delete')) : ?>
$(document).ready(function() {
	$('#tags').find('a').click(function() {
		var self = this;
                if(confirm('<?php echo addslashes($this->translator('tag_list_delete_confirm')); ?>')){
                    var id = $(self).parent().attr('id').split('_')[1];

                    $.ajax({
                            type: 'POST',
                            url: '<?php echo $this->url(array(), 'tag_tag_delete'); ?>',
                            data: { id: id },
                            success: function(response) {
                                    if ('RESULT_OK' == response) {
                                            $('#tag_' + id).fadeOut('slow');
                                    }else{
                                        alert('Have error');
                                    }
                                    
                            }
                    });
                }
		
	});
});
<?php endif; ?>
</script>
